/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2024-03-30
 * Time: 22:58
 */
//利用数组翻转
class Solution2 {
    public void rotate(int[] nums, int k) {
        k %= nums.length;
        reverse(nums, 0, nums.length - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.length - 1);

    }
    private void reverse (int[] nums, int start, int end) {
        while (start < end) {
            int temp = nums[start];
            nums[start] = nums[end];
            nums[end] = temp;
            start++;
            end--;
        }
    }
}
public class Method2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        int[] nums = {1,2,3,4,5,6,7};
        int k = 3;
        solution2.rotate(nums, k);
        for (int num : nums) {
            System.out.print(num + " ");
        }
    }
}
